package com.ruoyi.web.controller.customer;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.supe.TerraceTel;
import com.ruoyi.system.service.customer.TerraceTelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/terrace/tel")
public class TerraceTelController extends BaseController {


    @Autowired
    private TerraceTelService terraceTelService;

    /**
     * 查询平台电话列表
     */
    @PreAuthorize("@ss.hasPermi('terrace:tel:list')")
    @GetMapping("/list")
    public TableDataInfo list(TerraceTel terraceTel)
    {
        startPage();
        List<TerraceTel> list = terraceTelService.selectTerraceTelList(terraceTel);
        return getDataTable(list);
    }

    /**
     * 导出平台电话列表
     */


    @GetMapping("/export")
    public AjaxResult export(TerraceTel terraceTel)
    {
        List<TerraceTel> list = terraceTelService.selectTerraceTelList(terraceTel);
        ExcelUtil<TerraceTel> util = new ExcelUtil<TerraceTel>(TerraceTel.class);
        return util.exportExcel(list, "tel");
    }

    /**
     * 获取平台电话详细信息
     */

    @GetMapping(value = "/{telId}")
    public AjaxResult getInfo(@PathVariable("telId") Integer telId)
    {
        return AjaxResult.success(terraceTelService.selectTerraceTelById(telId));
    }

    /**
     * 新增平台电话
     */

    @PostMapping
    public AjaxResult add(@RequestBody TerraceTel terraceTel)
    {
        return toAjax(terraceTelService.insertTerraceTel(terraceTel));
    }

    /**
     * 修改平台电话
     */

    @PutMapping
    public AjaxResult edit(@RequestBody TerraceTel terraceTel)
    {
        return toAjax(terraceTelService.updateTerraceTel(terraceTel));
    }

    /**
     * 删除平台电话
     */

    @DeleteMapping("/{telIds}")
    public AjaxResult remove(@PathVariable Integer[] telIds)
    {
        return toAjax(terraceTelService.deleteTerraceTelByIds(telIds));
    }

}
